package actions;

import java.sql.SQLException;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Applicant;
import model.Database;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import forms.ResidencySubmitForm;
import model.*;

public class ResidencySubmitAction extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws DbException {
		
		HttpSession session = request.getSession();
		Applicant applicant = (Applicant) session.getAttribute("applicant");
		ResidencySubmitForm iForm = (ResidencySubmitForm) form;
		String applicantType;
		
		if(iForm.getResidency().equals("US Permanent Resident")){
			applicantType = "Domestic Applicant";
		}else{
			applicantType = "International Applicant";
		}
		
		applicant.setDomestic(applicantType);
		session.setAttribute("applicant", applicant);
		Vector<Degree> degreeVector = new Vector<Degree>();
		Vector<String> locationsVector=null;
		Vector<String> disciplinesVector = null;
		Vector<String> specializationsVector = null;
		
		try {
			specializationsVector = Database.getSpecializations();
			disciplinesVector = Database.getDisciplines();
			locationsVector = Database.getLocations();	// Should grab all of the universities specific to that Location 
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		session.setAttribute("locationsVector", locationsVector);
		session.setAttribute("degreeVector", degreeVector);
		session.setAttribute("specializationsVector", specializationsVector);
		session.setAttribute("disciplinesVector", disciplinesVector);

		return mapping.findForward("success");
	}
	
	
}

